package com.ctgu.computer.mapper;

import com.ctgu.computer.annotation.FillNowTime;
import com.ctgu.computer.domain.dto.FirstPageCommentDTO;
import com.ctgu.computer.domain.po.CommentInfo;
import com.ctgu.computer.domain.po.CommentTextSenderInfo;
import com.ctgu.computer.domain.po.GoodComment;
import com.ctgu.computer.domain.po.UserIdToCommentIds;
import com.ctgu.computer.domain.vo.FirstPageCommentVO;
import com.github.pagehelper.Page;
import io.swagger.v3.oas.annotations.media.Schema;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface CommentMapper {
    @FillNowTime
    void insert(CommentInfo commentInfo);

    void insertCommentTextSenderInfo(CommentTextSenderInfo commentTextSenderInfo);

    Page<CommentTextSenderInfo> firstPageCommentPage(FirstPageCommentDTO firstPageCommentDTO);

    @MapKey("commentId")
    Map<Integer,CommentInfo> getCommentsByIds(List<Integer> commentIds);

    @Select("select * from comment_text_sender_info where comment_id=#{commentId}")
    CommentTextSenderInfo getCommentTextSender(Integer commentId);

    @Select("select * from comment_text_sender_info where first_comment_id=#{commentId} order by id desc")
    Page<CommentTextSenderInfo> getCommentTextSenderListByCallCommentId(Integer commentId);

    @Delete("delete from comment_text_sender_info where comment_id = #{commentId}")
    void deleteCommentTextSender(Integer commentId);

    void batchDelete(List<Integer> commentIds);

    @Select("select * from comment_good_user where gooder_id=#{userId} and comment_id=#{commentId}")
    GoodComment selectGood(Integer commentId, Integer userId);

    @FillNowTime
    @Insert("insert into comment_good_user (comment_id, gooder_id, create_time, is_good) VALUES " +
            "(#{commentId},#{gooderId},#{createTime},#{isGood})")
    void insertGood(GoodComment goodComment);

    @FillNowTime
    @Update("update comment_good_user set is_good=#{isGood},create_time=#{createTime} " +
            "where gooder_id=#{gooderId} and comment_id=#{commentId}")

    void updateGood(GoodComment goodComment);

    @Select("select * from comment_info where comment_id=#{commentId}")
    CommentInfo selectById(Integer commentId);

    @FillNowTime
    @Update("update comment_info set good_count=#{goodCount} where comment_id=#{commentId}")
    void update(CommentInfo commentInfo);

    List<Integer> batchSelect(UserIdToCommentIds userIdToCommentIds);

    @Delete("delete from comment_good_user where !is_good")
    void batchDeleteGood();
}
